﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using BEPUphysics.Entities;
using Microsoft.Xna.Framework;

namespace Asplode.Renderer
{
    public class AsplodeRenderer
    {
        public List<RenderPair> models = new List<RenderPair>();
        public Game game;

        public AsplodeRenderer(Game game1){
            game = game1;
        }

        public void Draw(){
            foreach (RenderPair renderpair in models)
            {

                Matrix worldMatrix = renderpair.transform * renderpair.Entity.worldTransform;

                renderpair.Model.CopyAbsoluteBoneTransformsTo(renderpair.boneTransforms);
                
                foreach (ModelMesh mesh in renderpair.Model.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.World = renderpair.boneTransforms[mesh.ParentBone.Index] * worldMatrix;
                        effect.View = Matrix.CreateLookAt(game.Map.CameraPosition, Vector3.Zero, Vector3.Up);
                        effect.Projection = game.Map.CameraProjection;
                    }
                    mesh.Draw();
                }
            }
        }
    }    
}
